package com.mogu_soup.entity;

import java.awt.*;

/**
* Version: 2.1
* Author: TangJun
* Date: 2024-08-02
* Note:
*/
public abstract class Entity {


    //移动方向
    public static final int DIR_UP = 0;
    public static final int DIR_DOWN = 1;
    public static final int DIR_LEFT = 2;
    public static final int DIR_RIGHT = 3;


    protected int x, y;//坐标
    protected int speed;//速度
    protected int dir;//方向
    protected int size;//大小
    protected int atk;//攻击力
    public int hp;//血量
    protected boolean isLive;//状态

    /**
     * 判断点是否在物体内部
     * @param rectX 正方形中心点x
     * @param rectY 正方形中心点y
     * @param size 正方形边长
     * @param x 需要判断的点的x
     * @param y 需要判断的点的y
     * @return true为在内部
     */
    public static boolean isCollide(int rectX, int rectY, int size, int x, int y) {
        int disX = Math.abs(rectX - x);
        int disY = Math.abs(rectY - y);
        int radius = size / 2;
        return disX < radius && disY < radius;
    }

    //小矩形碰大矩形
    public static boolean isCollideEntity(int rectX, int rectY, int rectSize, int pointX, int pointY, int pointSize, int dir) {
        boolean ret  = false;
        int pointRadius = pointSize / 2;
        switch (dir) {
            case DIR_UP:
                //上面两个点
                ret = isCollide(rectX, rectY, rectSize, pointX - pointRadius, pointY - pointRadius)
                         || isCollide(rectX, rectY, rectSize, pointX + pointRadius, pointY - pointRadius);
                break;
            case DIR_DOWN:
                //下面两个点
                ret = isCollide(rectX, rectY, rectSize, pointX - pointRadius, pointY + pointRadius)
                        || isCollide(rectX, rectY, rectSize, pointX + pointRadius, pointY + pointRadius);
                break;
            case DIR_LEFT:
                //左边两个点
                ret = isCollide(rectX, rectY, rectSize, pointX - pointRadius, pointY - pointRadius)
                        || isCollide(rectX, rectY, rectSize, pointX - pointRadius, pointY + pointRadius);
                break;
            case DIR_RIGHT:
                //右边两个点
                ret = isCollide(rectX, rectY, rectSize, pointX + pointRadius, pointY - pointRadius)
                        || isCollide(rectX, rectY, rectSize, pointX + pointRadius, pointY + pointRadius);
                break;
            default:
                break;
        }
        return ret;
    }



    public abstract void draw(Graphics g);

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public int getDir() {
        return dir;
    }

    public int getSize() {
        return size;
    }
}
